//
//
//  打印机设置界面
//
//


import QtQuick
import QtQuick.Controls.Material

Item {
    id: printerSettingWindowRoot
    width: rootWidth
    height: rootHeight /*- 150*/

    Component.onCompleted: {
        console.log("生成！！ - 打印机设置界面")
        Cpp_PLC.QML_CurrentPage = 10;
    }

    Rectangle{
        anchors.top: printerSettingWindowRoot.top
        anchors.topMargin: 10
        anchors.horizontalCenter: printerSettingWindowRoot.horizontalCenter
        color: "transparent"
        border.width: 1
        width: 1060
        height: 730

        Text{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 20
            font.pixelSize: 50
            font.bold: true
            text: qsTr("打印机设定")
        }

        A_Label{
            anchors.left: parent.left
            anchors.leftMargin: 300
            anchors.top: parent.top
            anchors.topMargin: 150
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("高 度")
            visible: !Cpp_PLC.MechineChangeAngleMode
        }

        // A_TextInput{
        //     anchors.left: parent.left
        //     anchors.leftMargin: 530
        //     anchors.top: parent.top
        //     anchors.topMargin: 150
        //     validatorFlag : false
        //     inputWidth: 300
        //     maxDataLength: 8
        //     showData: Cpp_Printer.MaterialHeight

        //     onInputFinished: {
        //         Cpp_Printer.MaterialHeight = inputData
        //     }

        // }
        A_Label{
            id: material_Height_Label
            anchors.left: parent.left
            anchors.leftMargin: 530
            anchors.top: parent.top
            anchors.topMargin: 150
            labelBack: "white"
            labelBorderColor: "black"
            label_Data: Cpp_PLC.MaterialHeightValue
            visible: !Cpp_PLC.MechineChangeAngleMode
        }

        A_Label{
            anchors.left: parent.left
            anchors.leftMargin: 300
            anchors.top: parent.top
            anchors.topMargin: 240
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("长 度")
        }

        // A_TextInput{
        //     anchors.left: parent.left
        //     anchors.leftMargin: 530
        //     anchors.top: parent.top
        //     anchors.topMargin: 240
        //     inputWidth: 300
        //     maxDataLength: 8
        //     validatorFlag : false

        //     showData: Cpp_Printer.MaterialLength

        //     onInputFinished: {
        //         Cpp_Printer.MaterialLength = inputData
        //     }
        // }
        A_Label{
            id: material_Length_Label
            anchors.left: parent.left
            anchors.leftMargin: 530
            anchors.top: parent.top
            anchors.topMargin: 240
            labelBack: "white"
            labelBorderColor: "black"
            label_Data: Cpp_PLC.Wait_Worked_MaterialLength
        }

        A_Label{
            anchors.left: parent.left
            anchors.leftMargin: 300
            anchors.top: parent.top
            anchors.topMargin: 330
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("左 角 度")
        }

        A_Label{
            id: leftAngle_Label
            anchors.left: parent.left
            anchors.leftMargin: 530
            anchors.top: parent.top
            anchors.topMargin: 330
            labelBack: "white"
            labelBorderColor: "black"
            label_Data: Cpp_PLC.LeftAngleFeedBack ? qsTr("90") : qsTr("45")
        }

        // A_TextInput{
        //     anchors.left: parent.left
        //     anchors.leftMargin: 530
        //     anchors.top: parent.top
        //     anchors.topMargin: 330
        //     inputWidth: 100
        //     maxDataLength: 3
        //     validatorFlag : false

        //     showData: Cpp_Printer.LeftAngle

        //     onInputFinished: {
        //         Cpp_Printer.LeftAngle = inputData
        //     }
        // }

        A_Label{
            anchors.left: parent.left
            anchors.leftMargin: 300
            anchors.top: parent.top
            anchors.topMargin: 420
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("右 角 度")
        }

        A_Label{
            id: rightAngle_Label
            anchors.left: parent.left
            anchors.leftMargin: 530
            anchors.top: parent.top
            anchors.topMargin: 420
            labelBack: "white"
            labelBorderColor: "black"
            label_Data: Cpp_PLC.RightAngleFeedBack ? qsTr("90") : qsTr("45")
        }

        // A_TextInput{
        //     anchors.left: parent.left
        //     anchors.leftMargin: 530
        //     anchors.top: parent.top
        //     anchors.topMargin: 420
        //     inputWidth: 100
        //     maxDataLength: 3
        //     validatorFlag : false

        //     showData: Cpp_Printer.RightAngle

        //     onInputFinished: {
        //         Cpp_Printer.RightAngle = inputData
        //     }
        // }

        A_Label{
            anchors.left: parent.left
            anchors.leftMargin: 300
            anchors.top: parent.top
            anchors.topMargin: 510
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("型材名称")
        }

        A_TextInput{
            id: materialName_Input
            anchors.left: parent.left
            anchors.leftMargin: 530
            anchors.top: parent.top
            anchors.topMargin: 510
            inputWidth: 400
            maxDataLength: 15
            validatorFlag : false

            showData: Cpp_Printer.MaterialName

            onInputFinished: {
                Cpp_Printer.MaterialName = inputData
            }
        }

        A_Label{
            anchors.left: parent.left
            anchors.leftMargin: 300
            anchors.top: parent.top
            anchors.topMargin: 600
            labelBack: "transparent"
            labelBorderColor: "transparent"
            label_Data: qsTr("客 户")
        }

        A_TextInput{
            id: customName_Input
            anchors.left: parent.left
            anchors.leftMargin: 530
            anchors.top: parent.top
            anchors.topMargin: 600
            inputWidth: 400
            maxDataLength: 15
            validatorFlag : false

            showData: Cpp_Printer.Customer_Name

            onInputFinished: {
                Cpp_Printer.Customer_Name = inputData
            }

        }





    }

    Rectangle{
        anchors.top: printerSettingWindowRoot.top
        anchors.topMargin: 750
        anchors.left: printerSettingWindowRoot.left
        anchors.leftMargin: 10
        color: "transparent"
        border.width: 1
        width: 300
        height: 240

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.top: parent.top
            anchors.topMargin: 10
            font.pixelSize:  Cpp_Config.Language_Type === 0 ? 30 :  Cpp_Config.Language_Type === 1 ? 20 : 20
            font.bold: true
            text: qsTr("当前打印机")
        }

        RadioButton{
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.top: parent.top
            anchors.topMargin: 60
            font.pixelSize:  Cpp_Config.Language_Type === 0 ? 30 :  Cpp_Config.Language_Type === 1 ? 20 : 20
            font.bold: true
            checked: Cpp_Config.Printer_Type === 1 ? true : false

            text: qsTr("瑞工 RG_EL58")

            onClicked: {
                Cpp_Config.Printer_Type = 1
                Cpp_Printer.CurrentType = 1
            }
        }
        RadioButton{
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.top: parent.top
            anchors.topMargin: 120
            font.pixelSize:  Cpp_Config.Language_Type === 0 ? 30 :  Cpp_Config.Language_Type === 1 ? 20 : 20
            font.bold: true
            checked: Cpp_Config.Printer_Type === 2 ? true : false

            text: qsTr("炜煌 P16")

            onClicked: {                
                Cpp_Config.Printer_Type = 2
                Cpp_Printer.CurrentType = 2
            }
        }

        RadioButton{
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.top: parent.top
            anchors.topMargin: 180
            font.pixelSize:  Cpp_Config.Language_Type === 0 ? 30 :  Cpp_Config.Language_Type === 1 ? 20 : 20
            font.bold: true
            checked: Cpp_Config.Printer_Type === 3 ? true : false

            text: qsTr("达普 DP-EH240L")

            onClicked: {
                Cpp_Config.Printer_Type = 3
                Cpp_Printer.CurrentType = 3
            }
        }

    }

    Rectangle{
        anchors.top: printerSettingWindowRoot.top
        anchors.topMargin: 750
        anchors.right: printerSettingWindowRoot.right
        anchors.rightMargin: 10
        color: "transparent"
        border.width: 1
        width: 750
        height: 240

        A_Button{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 50
            // contentText_Fontsize: 30
            buttonWidth: 300
            contentText_Data: Cpp_PLC.M_511 ? qsTr("自动打印: 已启用") : qsTr("自动打印: 未启用")
            contentRectangle_BorderColor: Cpp_PLC.M_511 ? "gold" : "black"
            contentRectangle_BorderWidth: Cpp_PLC.M_511 ? 5 : 3

            // property bool flag: Cpp_PLC.M_511

            onButtonPressedAndHold: {
                // console.log("长按触发")
                // flag = !flag
                if(Cpp_PLC.M_511)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(511,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(511,"1")
                }
            }
        }

        A_Button{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 450
            // contentText_Fontsize: 30
            contentText_Data: qsTr("手 动 打 印")

            onButtonClicked: {
                // Cpp_Printer.printerActive(material_Height_Label.label_Data)
                // console.log(material_Height_Label.label_Data)
                // console.log(material_Length_Label.label_Data)
                // console.log(leftAngle_Label.label_Data)
                // console.log(rightAngle_Label.label_Data)
                // console.log(materialName_Input.showData)
                // console.log(customName_Input.showData)

                Cpp_Printer.printerActive(material_Height_Label.label_Data,
                                          material_Length_Label.label_Data,
                                          leftAngle_Label.label_Data,
                                          rightAngle_Label.label_Data)
                                          // materialName_Input.showData,
                                          // customName_Input.showData)
            }

        }

    }


}
